package com.sk.bilibili.model.fragment.search;

import com.sk.api.annotations.Autowired;
import com.sk.bilibili.bean.Focus;
import com.sk.bilibili.bean.Member;
import com.sk.bilibili.callBack.RequestCallBack;
import com.sk.bilibili.dto.Page;
import com.sk.bilibili.mapper.FocusMapper;
import com.sk.bilibili.mapper.SearchMapper;
import com.sk.bilibili.other.JsonMap;
import com.sk.bilibili.utils.RequestUtils;
import com.sk.bilibili.view.fragment.search.MemberFragment;

public class MemberModel extends BaseSearchModel<MemberFragment>{

    @Autowired
    SearchMapper searchMapper;
    @Autowired
    FocusMapper focusMapper;

    @Override
    public void loadData() {
        JsonMap map = getJsonMap();
        RequestUtils.process(searchMapper.searchMember(map), memberPage -> {
            view.addData(memberPage.getRecords());
            page++;
        });
    }

    @Override
    public void refreshData() {
        page=1;
        JsonMap map = getJsonMap();
        RequestUtils.process(searchMapper.searchMember(map), memberPage -> {
            view.setData(memberPage.getRecords());
            view.setNum(memberPage.getTotal());
            page++;
        });
    }

    public void switchFocus(Integer focusId) {
        RequestUtils.process(focusMapper.switchFocus(focusId),
                focus -> view.switchFocusSuccess(focus));
    }

}